package guilddto

import (
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/util/gconv"
	"strconv"
	"xr-game-server/entity"
)

type MemberRoleDto struct {
	RoleId   string `json:"roleId" summary:"角色ID"`
	Nick     string `json:"nick" summary:"昵称"`
	AvatarId uint32 `gorm:"default:0;comment:头像框id"`
}

func NewMemberRoleDto(role *entity.PlayerRole) *MemberRoleDto {
	ret := new(MemberRoleDto)
	gconv.Struct(role, ret)
	ret.RoleId = strconv.FormatUint(role.ID, 10)
	return ret
}

// 公会成员信息
type GuildMemberInfo struct {
	RoleInfo *MemberRoleDto `json:"roleInfo"`
	Title    uint8          `json:"title" summary:"头衔"`
	JoinTime string         `json:"joinTime" summary:"加入时间"`
}

// 获取公会成员信息请求
type GuildMemberInfoReq struct {
	g.Meta  `path:"/member" method:"post" summary:"获取公会成员信息" tags:"公会"`
	GuildId uint64 `json:"guildId" v:"required" summary:"公会ID"`
}

type GuildMemberInfoRes struct {
	Members []*GuildMemberInfo `json:"members" summary:"成员列表"`
}

func NewGuildMemberInfoRes() *GuildMemberInfoRes {
	return &GuildMemberInfoRes{
		Members: make([]*GuildMemberInfo, 0),
	}
}

// 将entity.GuildMember转换为GuildMemberInfo
func NewGuildMemberInfo(member *entity.GuildMember, role *entity.PlayerRole) *GuildMemberInfo {
	ret := new(GuildMemberInfo)
	ret.RoleInfo = NewMemberRoleDto(role)
	gconv.Struct(member, ret)
	ret.JoinTime = member.UpdatedAt.Format("2006-01-02 15:04:05")
	return ret
}

// 推送刷新成员列表
type PushRefreshGuildMemberReq struct {
	g.Meta `path:"/pushRefreshGuildMember" method:"post" summary:"推送刷新成员列表" dc:"命令=22" tags:"公会"`
}
type PushRefreshGuildMemberRes struct {
	Cmd uint16 `json:"cmd" summary:"命令"`
}
